package com.example.play.controller;






import com.api.core.exception.ServiceException;
import com.example.play.entity.Food;
import com.example.play.entity.User;
import com.example.play.service.UserService;
import com.api.core.result.JsonResponse;
import com.api.core.result.PageView;
import com.example.play.request.UserPageReq;
import com.example.play.request.UserReq;
import com.example.play.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.logging.Logger;

import static com.api.core.result.JsonResponse.success;

/**
 * 用户(User)表控制层
 *
 * @author makejava
 * @since 2022-02-26 11:32:17
 */
@Api(tags = "用户(User)")
@RestController
@RequestMapping("user")
@Slf4j
public class UserController {

    /**
     * 服务对象
     */
     @Resource
    private UserService userService;
 
    @PostMapping("/addUser")
    @ApiModelProperty("发布用户 ")

    public JsonResponse addUser(@RequestBody UserReq userReq) {

        return JsonResponse.success (userService.addUser (userReq));
    }

    @PostMapping("/findUserList")
    @ApiModelProperty("查询用户 列表")
    public JsonResponse<PageView<User>> findUserList(@RequestBody UserPageReq userPageReq) {

       return JsonResponse.success ( userService.findUserList (userPageReq));
                
    }
    /**
     * 用户登录接口
     *
     * @param account  账号
     * @param password 密码
     * @return userDto
     */
    @PostMapping("/userLogin")
    @ApiOperation("用户登录")
    public JsonResponse userLogin(@ApiParam(value = "账号") @RequestParam String account,
                                  @ApiParam(value = "密码") @RequestParam String password
    ) throws ServiceException {
        return success (userService.userLogin (account, password));
    }
    @GetMapping("/getUserById")
    @ApiModelProperty("查询用户 详情")
    public JsonResponse getUserById(@RequestParam Integer userId) {

        return JsonResponse.success (userService.getUserById (userId));
    }

    @GetMapping("/deleteUser")
    @ApiModelProperty("删除用户 ")
    public JsonResponse deleteUser(@RequestParam Integer userId) {

        return JsonResponse.success (userService.deleteUser (userId));
    }
    @PostMapping("/updateUser")
    @ApiModelProperty("修改 ")
    public JsonResponse updateUser(@RequestBody User user) {

        return JsonResponse.success (userService.update (user));
    }
}
